$(document).ready(function(){
    $show = $(".tour_shows");
    $items = $("#infototit ul li a");
    $show.eq(0).show();
    $items.click(function(){
        $(".selected").removeClass("selected");
        $(this).addClass("selected");
        $val = $(this).attr("name");
        $show.hide();
        $show.eq($val).show();
        return false;
    });
});
function book() {
    var name_b = $('#name_b').val();
    if(name_b == ''){
        alert('You must fill in this place');
        $('#name_b').focus();
        return false;
    }
    var mail_b = $('#mail_b').val();
    if(checkEmail(mail_b) == false){
        $('#mail_b').focus();
        alert('Invalid email address');
        return false;
    }
    var con_b = $('#con_b').val();
    var add_b = $('#add_b').val();
    var phone_b = $('#phone_b').val();
    if( isValidPhone(phone_b) == false){
        $('#phone_b').focus();
        alert('Invalid phone');
        return false;
    }
    var tname_b = $('#tname_b').val();
    var tid_b = $('#tid_b').val();
    var adu_b = $('#adu_b').val();
    if(adu_b == ''){
        alert('You must fill in this place');
        $('#adu_b').focus();
        return false;
    }
    var chi_b = $('#chi_b').val();
    var date_b = $('#date_b').val();
    if(date_b == ''){
        alert('You must fill in this place');
        $('#date_b').focus();
        return false;
    }
    if($("input[type='radio'].diet").is(':checked')) {
        var diet = $("input[type='radio'].diet:checked").val();
    }else {
        var diet = 0;
    }
    if($("input[type='radio'].call_b").is(':checked')) {
        var call_b = $("input[type='radio'].call_b:checked").val();
    }else {
        var call_b = 0;
    }
    var indi_b = $('#indi_b').val();
    var find_b = $('#find_b').change().val();
    var conten_b = $('#conten_b').val();
	document.getElementById("loading").style.display = "block";
    $.ajax({
        type:'post',
        url: links + "home/tours/book",
        data:{name_b:name_b, mail_b:mail_b, con_b:con_b, add_b:add_b, phone_b:phone_b, tname_b:tname_b, tid_b:tid_b,
            adu_b:adu_b, chi_b:chi_b, date_b:date_b, diet:diet, call_b:call_b, indi_b:indi_b, find_b:find_b, conten_b:conten_b},
        beforeSend : function(){
            $("#loading").html("<img src='"+links+"public/images/loading.gif' /> Processing...");
        },
        success: function(){
            $('#name_b').val('');
            $('#mail_b').val('');
            $('#phone_b').val('');
            $('#con_b').val('');
            $('#add_b').val('');
            $('#date_b').val('');
            $('#adu_b').val('');
            $('#chi_b').val('');
            $('#indi_b').val('');
            $('#conten_b').val('');
            window.location = links+"thank.html";
        }
    });
    return false;
}
function sendcus() {
    var name = $('#name_cus').val();
    if(name == ''){
        alert('You must fill in this place');
        $('#name_cus').focus();
        return false;
    }
    var add = $('#add_cus').val();
    var cat = $('#cat_cus').change().val();
    var con = $('#con_cus').change().val();
    var phone = $('#phone_cus').val();
    if( isValidPhone(phone) == false){
        $('#phone_cus').focus();
        alert('Invalid phone');
        return false;
    }
    var email = $('#email_cus').val();
    if(checkEmail(email) == false){
        $('#email_cus').focus();
        alert('Invalid email address');
        return false;
    }
    var adu = $('#peo_cus').change().val();
    if(adu == ''){
        alert('You must fill in this place');
        $('#peo_cus').focus();
        return false;
    }
    var chi = $('#chi_cus').change().val();
    if(chi == ''){
        alert('You must fill in this place');
        $('#chi_cus').focus();
        return false;
    }
    var date = $('#date_cus').val();
    if(date == ''){
        alert('You must fill in this place');
        $('#date_cus').focus();
        return false;
    }
    var dura = $('#dura_cus').change().val();
    var content = $('#content_cus').val();
    var tour_id = $('#tour_id_cus').val();
    var tour_name = $('#tour_name_cus').val();

    $.ajax({
        type:'post',
        url: links + "home/tours/custours",
        data:{name:name, add:add, cat:cat, con:con, phone:phone, email:email, adu:adu,
            chi:chi, date:date, dura:dura, content:content, tour_id:tour_id, tour_name:tour_name},
        success: function(){
            var name = $('#name_cus').val('');
            var add = $('#add_cus').val('');
            var cat = $('#cat_cus').change().val('');
            var con = $('#con_cus').change().val();
            var phone = $('#phone_cus').val('');
            var email = $('#email_cus').val('');
            var adu = $('#peo_cus').change().val('');
            var chi = $('#chi_cus').change().val('');
            var date = $('#date_cus').change().val('');
            var dura = $('#dura_cus').change().val('');
            var content = $('#content_cus').val('');
            window.location = links+"thank.html";
        }
    });
    return false;
}
function contact() {
    var name = $('#namec').val();
    if(name == ''){
        alert('You must fill in this place');
        $('#namec').focus();
        return false;
    }
    var email = $('#mailc').val();
    if(checkEmail(email) == false){
        alert('Invalid email address');
        $('#mailc').focus();
        return false;
    }
    var coc = $('#coc').val();
    if(coc == ''){
        alert('You must fill in this place');
        $('#coc').focus();
        return false;
    }

    var sc = $.trim($('#sc').val());
    if(sc == ''){
        alert('You must fill in this place');
        $('#sc').focus();
        return false;
    }
    var finc = $('#finc').change().val();
    var mesc = $('#mesc').val();
    if(mesc == ''){
        alert('You must fill in this place');
        $('#mesc').focus();
        return false;
    }
	document.getElementById("loading").style.display = "block";
    $.ajax({
        type: "post",
        url: links+"home/contact/add",
        data: {name:name, email:email, coc:coc, sc:sc, finc:finc, mesc:mesc},
        success: function(data){
            window.location = links+"thank.html";
        }
    });
    return false;
}
function checkEmail(inputvalue){
    var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/;
    if(pattern.test(inputvalue)){
        return true;
    }else{
        return false;
    }
}
function isValidPhone(phone){
    var reg = /^[0-9-+]+$/;
    return reg.test(phone)
}
function hidemap(){
	$('#infotourr').hide();
	$('#infotourl').css("width","928px" );
}
function showmap() {
	$('#infotourr').show();
	$('#infotourl').css("width","561px" );

}
$(function() {
    $("#date1").datepicker();
    $("#date_b").datepicker();
    $("#date_cus").datepicker();
    $("a.example1").fancybox();
});